import os
import datetime

class MyDes:
    def __init__(self, val, name):
        self.value1 = val
        self.name = name
        self.fileName = 'record.txt'
    
    def __get__(self, instance, owner):
        with open(self.fileName,'a',encoding='utf-8') as f:
            f.write("%s 变量于北京时间 %s 被读取，%s = %s\n" % (self.name,str(datetime.datetime.now()),self.name,str(self.value1)))
        return self.value1

    def __set__(self, instance, value):
        fileName = "%s_record.txt" % self.name
        with open(self.fileName,'a',encoding='utf-8') as f:
            f.write('%s 变量于北京时间 %s 被修改，%s = %s\n' % (self.name,str(datetime.datetime.now()),self.name,str(self.value1)))
        self.value1 = value

    

class Test:
    x = MyDes(10, 'x')
    y = MyDes(8.8, 'y')


test = Test()
print(test.x)
print(test.y)
test.x = 123
test.x = 1.23
test.y = 'i ccccccccccccc'

